package com.dc.refactoring._5_简化函数调用._4_SeparateQueryFromModifier;

import java.util.List;
import java.util.Objects;

public class NewDemo {


    void checkSecurity(List<String> peoples){

        sendAlert(peoples);

        someLaterCode(foundPerson(peoples));

    }

    // 将查询的逻辑提取出来
    String foundPerson(List<String> peoples) {
        for (String people: peoples) {
            if (Objects.equals(people, "Don")) {
                return "Don";
            } else if (Objects.equals(people, "John")) {
                return "John";
            }
        }
        return "";
    }

    // 修改剩余发送逻辑的判断
    void sendAlert(List<String> peoples) {
        if (!Objects.equals(foundPerson(peoples), "")) {
            sendAlert();
        }
    }

    private void sendAlert() {
         System.out.println("SEND");
    }

    private void someLaterCode(String found) {
    }

}
